<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="false">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row :gutter="48">
          <a-col :span="24">
            <a-form-model-item label="款项名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="kxmc">
              <a-input :disabled=formDisabled v-model="model.kxmc" placeholder="请输入款项名称"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="je">
              <a-input-number :disabled=formDisabled  v-model="model.je" placeholder="请输入金额" :min="model.collectMoney"
                              style="width: 100%"/>
              <span v-if="warnShow" style="color: red">
                <span v-if="this.htlx == '1'"> 当前款项已收{{model.collectMoney}}元 , 金额调整不可低于实收金额</span>
                <span v-if="this.htlx == '2'"> 当前款项已付{{model.collectMoney}}元 , 金额调整不可低于实付金额</span>
              </span>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="预计款项日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="kxrq">
              <j-date :disabled=formDisabled placeholder="请选择预计款项时间" v-model="model.kxrq" style="width: 100%"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="款项节点说明" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="kxjdsm">
              <a-input :disabled=formDisabled v-model="model.kxjdsm" placeholder="请输入款项节点说明"></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>
import { message } from 'ant-design-vue';
import { getAction } from '@api/manage';
export default {
  name: 'OldErpOmcContractManagerPlanForm',
  components: {},
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    },
    htlx: {
      type: String,
      default: '',
      required: false
    },
    // 合同金额
    bchte:{
      type:Number,
      default:0
    }
  },
  data() {
    return {
      warnShow: false,
      // 最大和输入金额
      model: {},
      labelCol: {},
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 24 },
      },
      confirmLoading: false,
      validatorRules: {
        kxmc: [
          { required: true, message: '请选择款项名称!' }
        ],
        je: [
          // { required: true, pattern: /^(([1-9][0-9]*)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确的金额!' }
          { required: true, pattern: /^-?(([0-9]*(\.[0-9]{1,3})$)|([0-9]+$))/, message: '请输入正确的金额!' }
        ],
        kxrq: [
          { required: true, message: '请选择预计款项日期!' }
        ],
        kxjdsm: [
          { required: true, message: '请选择款项节点说明!' }
        ]
      },
      url: {
        add: '/api/erp/omc/contractmanager/erpOmcContractManagerPlan/add',
        edit: '/api/erp/omc/contractmanager/erpOmcContractManagerPlan/edit',
        queryById: '/api/erp/omc/contractmanager/erpOmcContractManagerPlan/queryById',
        queryByApplyId: '/api/erp/omc/contractmanager/erpOmcContractManagerPlanFinal/queryByApplyId'
      }
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    },
  },
  created() {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model));
  },
  methods: {
    add() {
      this.edit(this.modelDefault);
    },
    edit(record) {
      this.$refs['form'].clearValidate();
      this.warnShow = false
      Object.assign(this.$data, this.$options.data())
      this.model = Object.assign({}, record);
      if (this.model.collectMoney) {
        this.warnShow = true
      }else{
        if (this.model.id) {
          // 查看合同档案
          getAction(this.url.queryByApplyId, { sealId: this.model.id }).then((res) => {
            if (res.success) {
              this.model.collectMoney = res.result.collectMoney
              if (this.model.collectMoney) {
                this.warnShow = true
              }
            }
          })
        }
      }
      this.visible = true;
    },
    submitForm() {
      const that = this;
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          // 金额是否合法
          if (!this.model.id) {
            this.model.id = parseInt(Math.random() * 1000000000000);
          }
          that.$emit('ok', this.model);
        }

      })
    },
  }
}
</script>
